package ui.controls;

import java.awt.Color;
import java.awt.Image;
import ui.components.ImageControl;
import ui.Assets;
import ui.control.led.*;
import ui.control.binary.States;

public class LED extends ImageControl implements ui.control.binary.Control {

	private States state;
	protected Image image;
	
	public LED( Assets assets, LEDColors color, LEDSizes size ) {
		
		if( color == LEDColors.RED )
			if( size == LEDSizes._16 )
				imagelist = assets.ledRed16;
			else
				imagelist = assets.ledRed24;
		else if( color == LEDColors.BLUE )
			if( size == LEDSizes._16 )
				imagelist = assets.ledBlue16;
			else
				imagelist = assets.ledBlue24;
		else if( color == LEDColors.GREEN )
			if( size == LEDSizes._16 )
				imagelist = assets.ledGreen16;
			else
				imagelist = assets.ledGreen24;
		else if( color == LEDColors.YELLOW )
			if( size == LEDSizes._16 )
				imagelist = assets.ledYellow16;
			else
				imagelist = assets.ledYellow24;
		else if( color == LEDColors.AMBER )
			if( size == LEDSizes._16 )
				imagelist = assets.ledAmber16;
			else
				imagelist = assets.ledAmber24;
		
		if( size == LEDSizes._16 ) {
			width = 16;
			height = 16;
		} else {
			width = 24;
			height = 24;
		}
		setSize( width, height);
		state = States.OFF;
		currentImage = 0;
		image = imagelist.image( currentImage );
	}
	public void setState( States state ) {
		switch( state ) {
		case OFF:
			currentImage = 0;
			image = imagelist.image( currentImage );
			this.state = States.OFF;
			repaint();
			break;
		case ON:
			currentImage = 1;
			image = imagelist.image( currentImage );
			this.state = States.ON;
			repaint();
			break;
		}
	}
	public States getState( ) {
		return state;
	}
	public States toggle( ) {
		switch( state ) {
		case OFF:
			setState( States.ON );
			break;
		case ON:
			setState( States.OFF );
			break;
		}
		return state;
	}
	public void toggleOn( ) {
		setState( States.ON );
	}
	public void toggleOff( ) {
		setState( States.OFF );
	}
}
